package com.demo.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.demo.domain.AdminBank;
import com.demo.model.R;
import com.demo.service.AdminBankService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

@RestController
@RequestMapping("/adminBanks")
public class AdminBankController {

    @Autowired
    private AdminBankService adminBankService;

    @GetMapping
    public R<Page<AdminBank>> findByPage(Page<AdminBank> page ,String bankCard){
       return R.ok(adminBankService.findByPage(page,bankCard));
    }

    @PostMapping
    public R add(@RequestBody @Validated AdminBank adminBank){
        boolean save = adminBankService.save(adminBank);
        if(save){
           return R.ok("新增成功");
        }
        return R.fail("新增失败");

    }

    @PatchMapping
    public R update(@RequestBody @Validated AdminBank adminBank){
        boolean update = adminBankService.updateById(adminBank);
        if(update){
            return R.ok("银行卡数据修改成功");
        }
        return R.fail("银行卡数据修改失败");

    }


    @PostMapping("/adminUpdateBankStatus")
    public R adminUpdateBankStatus(Long bankId,Integer status){
        AdminBank adminBank = new AdminBank();
        adminBank.setId(bankId);
        adminBank.setStatus(status);
        boolean update_status = adminBankService.updateById(adminBank);
        if(update_status){
            return R.ok("使用状态修改成功");
        }
        return R.fail("使用状态修改失败");
    }
}
